package cn.bincker.web.blog.base.repository;

import cn.bincker.web.blog.base.entity.FriendLink;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface IFriendLinkRepository extends JpaRepository<FriendLink, Long> {
    List<FriendLink> findAllByStatus(FriendLink.Status status);

    @Query(
            value = "from FriendLink where title like :keywords or url like :keywords",
            countQuery = "select count(FriendLink) from FriendLink  where title like :keywords or url like :keywords"
    )
    Page<FriendLink> findAllByKeywordsLike(String keywords, Pageable pageable);

    @Query(
            value = "from FriendLink where (title like :keywords or url like :keywords) and status = :status",
            countQuery = "select count(FriendLink) from FriendLink  where (title like :keywords or url like :keywords) and status = :status"
    )
    Page<FriendLink> findAllByKeywordsLike(String keywords, FriendLink.Status status, Pageable pageable);

    Optional<FriendLink> findByUrl(String url);
}
